import { Component,OnInit } from '@angular/core';

import { ToasterService, ToasterConfig, Toast, BodyOutputType } from 'angular2-toaster';

import { MainService,Comprehensive } from '../main.service';
import { Router } from '@angular/router';


@Component({
  selector: 'ngx-comprehensive',
  styleUrls: ['comprehensive.component.scss'],
  templateUrl: 'comprehensive.component.html',
})
export class ComprehensiveComponent implements OnInit {
  comphen: Comprehensive;
  config: ToasterConfig;

  constructor(private mainService: MainService,
              private toasterService: ToasterService,
              private router: Router) {}

  ngOnInit(): void {
    this.queryComprehensive();
  }

  queryComprehensive(): void {
    this.mainService.queryComprehensive()
      .subscribe(
        (data: Comprehensive) => this.comphen = data, // success path
        error => this.errorTodo(error)
      )
  }

  testRouterPam():void{
    var object = {'name':'yxman','age':10};
    this.router.navigate(['/pages/realtime'],{queryParams:object});
  }

  errorTodo(error): void{
    const toast: Toast = {
      type: 'error',
      title: '请求失败',
      body: 'json格式解释错误',
      bodyOutputType: BodyOutputType.TrustedHtml,
    };
    this.toasterService.popAsync(toast);
  }
}
